﻿using System;
using System.Collections.ObjectModel;
using FXSStation.Modules.SharedInfrastructureModule.BusinessClasses.Orders;
using FXSStation.Modules.SharedInfrastructureModule.BusinessClasses.Currency;
using System.ComponentModel;
using System.Collections.Generic;
using System.Linq;

namespace FXSStation.Modules.SharedInfrastructureModule.BusinessClasses.Accounts
{
    [Serializable]
    public class Session : INotifyPropertyChanged
    {
        #region Fields 

        private DateTime _timeStampStart;
        private DateTime _timeStampEnd;

        private CurrencyEnum _currencySymbol;
        
        private ObservableCollection<OrderBase> _activeOrders;
        private ObservableCollection<OrderBase> _closedOrders;

        private bool _isOpen;

        #endregion // Fields

        #region Properties

        public DateTime TimeStampStart
        {
            get { return _timeStampStart; }
            set { _timeStampStart = value; }
        }
        public DateTime TimeStampEnd
        {
            get { return _timeStampEnd; }
            set { _timeStampEnd = value; }
        }

        public CurrencyEnum CurrencySymbol
        {
            get { return _currencySymbol; }
            set
            {
                _currencySymbol = value;
                RaisePropertyChanged("CurrencySymbol");
            }
        }

        public ObservableCollection<OrderBase> ClosedOrders
        {
            get
            {
                return _closedOrders;
            }
            set
            {
                _closedOrders = value;
            }
        }
        public ObservableCollection<OrderBase> ActiveOrders
        {
            get
            {
                return _activeOrders;
            }
            set
            {
                _activeOrders = value;
            }
        }

        public bool IsOpen
        {
            get { return _isOpen; }
            set
            { 
                if(value!=_isOpen)
                {
                    _isOpen = value;
                    RaisePropertyChanged("IsOpen");
                }
            }
        }
        
        #endregion // Properties

        #region Constructors

        public Session(DateTime start, CurrencyEnum currency)
        {
            this._activeOrders = new ObservableCollection<OrderBase>();
            this._closedOrders = new ObservableCollection<OrderBase>();
            this._timeStampStart = start;
            this._currencySymbol = currency;
            // when a new session is created, it is open
            this._isOpen = true;
        }

        #endregion // Constructors

        #region INotifyPropertyChanged Members
        [field:NonSerialized]
        public event PropertyChangedEventHandler PropertyChanged;
        public void RaisePropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        #endregion
    } 
}
